# -*- coding: utf-8 -*-

from django.db import models

# Create your models here.

#权限组
class Sys_Team(models.Model):
    Title = models.CharField(max_length=50,verbose_name='名称',blank=True)
    
    class Meta:
        verbose_name = "权限组"
    def __unicode__(self):
        return self.Title
#用户
class User_Account(models.Model):
    UserId = models.CharField(max_length=36,primary_key=True,verbose_name='用户ID')
    NickName = models.CharField(max_length=50,verbose_name='昵称')
    State = models.IntegerField(verbose_name='状态')
    CreateTtime = models.DateTimeField(verbose_name='注册时间')
    TypeId = models.IntegerField(verbose_name='类型')
    PurviewTeamID=models.ForeignKey(Sys_Team,verbose_name='权限组ID')

    class Meta:
        ordering = ["CreateTtime","State"]
        verbose_name = "用户"
        
    def StateEnum(self):
        return [u"停用",u"启用"]
    
    def __unicode__(self):
        return self.NickName

        
#登录账号表
class User_Login(models.Model):
    Rowid = models.CharField(max_length=36,primary_key=True,verbose_name='自增')
    UserId = models.ForeignKey(User_Account,verbose_name='用户')
    Account = models.CharField(max_length=100,verbose_name='登录名')
    PassWord = models.CharField(max_length=32,verbose_name='密码')
    State =  models.IntegerField(verbose_name='绑定状态')
    Types =  models.IntegerField(verbose_name='绑定类型')#enum 0 本站 web #1 QQ QQ 2 微博 weibo
    CreateTtime = models.DateTimeField(verbose_name='创建时间')
    class Meta:
        verbose_name = "登录账号"
    def __unicode__(self):
        return self.Account
    
    def StateEnum(self):
        return [u"停用",u"启用"]
    def TypesEnum(self):
        return [u"本站",u"QQ",u"微博"]

    
    
# 文件表
class Sys_File(models.Model):
    FileId = models.CharField(max_length=36,primary_key=True,verbose_name='FileId')
    FileName = models.CharField(max_length=200,verbose_name='文件名称')
    Extension = models.CharField(max_length=10,verbose_name='文件扩展名')
    FilePath = models.CharField(max_length=200,verbose_name='文件保存路径')
    FileSize =  models.IntegerField(verbose_name='文件大小')
    IsBind = models.IntegerField(verbose_name='是否已绑定')
    UpTime = models.DateTimeField(verbose_name='上传时间')
    ModelId = models.CharField(max_length=36,verbose_name='关联ID',null=True)
    class Meta:
        verbose_name = "文件表"
    def __unicode__(self):
        return self.Title  
        
#管理员日志
class Sys_Log(models.Model):
    LogId = models.CharField(max_length=36,primary_key=True,verbose_name='日志ID')
    UserId = models.ForeignKey(User_Account,verbose_name='用户')
    ConText = models.CharField(max_length=300,verbose_name='内容',null=True)
    TypeId =  models.IntegerField(verbose_name='类型')
    LogTime = models.DateTimeField(verbose_name='日志时间')
    class Meta:
        verbose_name = "管理员日志"
    def __unicode__(self):
        return self.ConText
    
    def TypesEnum(self):
        return[u"登录",u"更改用户资料",u"创建用户",u"添加新闻",u"编辑新闻",u"删除新闻",u"审核新闻",u"审核留言",u"审核评论"]
  
#友情链接
class Sys_Link(models.Model):
    LinkId = models.CharField(max_length=36,primary_key=True,verbose_name='链接ID')
    Title = models.CharField(max_length=20,verbose_name='链接名称')
    WebUrl = models.CharField(max_length=200,verbose_name='URl',null=True)
    imgUrl = models.CharField(max_length=200,verbose_name='imgUrl',null=True)
    Sno =  models.IntegerField(verbose_name='排序级别')
    class Meta:
        verbose_name = "友情链接"
    def __unicode__(self):
        return self.Title
        
# 网站信息
class Sys_Info(models.Model):
    WebId = models.CharField(max_length=36,primary_key=True,verbose_name='WebId')
    Title = models.CharField(max_length=20,verbose_name='标题',null=True)
    WebUrl = models.CharField(max_length=400,verbose_name='内容',null=True)
    class Meta:
        verbose_name = "网站信息"
    def __unicode__(self):
        return self.Title    

# 留言板
class Message_Board(models.Model):
    MessageId = models.CharField(max_length=36,primary_key=True,verbose_name='MessageId')
    ApplyUserId = models.CharField(max_length=36,verbose_name='留言人ID')
    ApplyUserName = models.CharField(max_length=20,verbose_name='留言人名称',null=True)
    ApplyPhone = models.CharField(max_length=20,verbose_name='联系电话',null=True)
    ApplyMail = models.EmailField(verbose_name='联系邮箱',null=True)
    ApplyContent = models.CharField(max_length=500,verbose_name='留言内容',null=True)
    ApplyTime = models.DateTimeField(verbose_name='留言时间')
    ReplyUserId = models.CharField(max_length=36,verbose_name='回复ID',null=True)
    ReplyUserName = models.CharField(max_length=20,verbose_name='回复姓名',null=True)
    ReplyTime = models.DateTimeField(verbose_name='回复时间',null=True,blank=True)
    ReplyContent = models.CharField(max_length=500,verbose_name='留言内容',null=True)
    AnonymousReply = models.BooleanField(verbose_name='是否匿名留言')
    State = models.BooleanField(verbose_name='是否已回复')
    IsOpen = models.BooleanField(verbose_name='是否公开')
    class Meta:
        verbose_name = "留言板"
    def __unicode__(self):
        return self.ApplyContent    

#模版类别
class Article_Template(models.Model):
    TemplateName = models.CharField(max_length=50,verbose_name='模版名称',null=True)
    Explain = models.CharField(max_length=500,verbose_name='说明',null=True)
    class Meta:
        verbose_name = "模版类别"
    def __unicode__(self):
        return self.TemplateName
        
#分类列表
class Article_Type(models.Model):
    ArticleTypeid = models.CharField(max_length=36,primary_key=True,verbose_name='ArticleTypeid')
    Title = models.CharField(max_length=50,verbose_name='名称')
    SuperiorId = models.CharField(max_length=36,verbose_name='父分类')
    Path = models.CharField(max_length=500,verbose_name='分类路径',null=True)
    TemplateId = models.ForeignKey(Article_Template,verbose_name='模版类别')
    IsLock = models.BooleanField(verbose_name='是否锁定分类')
    class Meta:
        verbose_name = "分类列表"
    def __unicode__(self):
        return self.Title

        
# 内容表
class Article_Content(models.Model):
    ContentId = models.CharField(max_length=36,primary_key=True,verbose_name='发布内容Id')
    UserId = models.ForeignKey(User_Account,verbose_name='用户')
    Title = models.CharField(max_length=100,verbose_name='标题')
    ArticleTypeid =  models.ForeignKey(Article_Type,verbose_name='所属分类')
    TemplateId =  models.ForeignKey(Article_Template,verbose_name='模版类别')
    State = models.IntegerField(verbose_name='状态') #enum 1 正常  normal 2  审核中  verify 3  删除  del 4  草稿 draft
    KeyWords = models.CharField(max_length=200,verbose_name='关键字',null=True)
    Summary = models.CharField(max_length=500,verbose_name='摘要',null=True)
    FileId = models.CharField(max_length=36,verbose_name='图片ID')
    Click = models.IntegerField(verbose_name='点击率')
    Recommend = models.IntegerField(verbose_name='推荐度')
    TopNum = models.IntegerField(verbose_name='置顶级别')
    IsComment = models.BooleanField(verbose_name='是否开启评论')
    IsImage = models.BooleanField(verbose_name='是否包含封面图片')
    IsLogin = models.BooleanField(verbose_name='是否登录才能浏览')
    SubmitTime = models.DateTimeField(verbose_name='发布时间')
    UpateTime = models.DateTimeField(verbose_name='修改时间',null=True)
    OverTime = models.DateTimeField(verbose_name='结束时间',null=True)
    CommentNum = models.IntegerField(verbose_name='评论数量')
    class Meta:
        verbose_name = "内容表"
    def __unicode__(self):
        return self.Title
    def TemplateEnum(self):
        return[u'',u"普通",u"图片",u"视频",u"投票",u"招聘",u'软件',u'商品'] 
    def StateEnum(self):
        return [u"删除",u"正常",u"审核中",u"草稿",u"未知"]

#评论表
class Article_Comment(models.Model):
    CommentId = models.CharField(max_length=36,primary_key=True,verbose_name='评论id')
    UserId = models.ForeignKey(User_Account,verbose_name='用户')
    ContentId = models.ForeignKey(Article_Content,verbose_name='内容Id')
    ConText = models.CharField(max_length=500,verbose_name='评论内容',null=True)
    State = models.IntegerField(verbose_name='状态') #enum 1 正常   normal  2 未审核 not 3  删除 del
    Ip = models.IPAddressField(verbose_name='用户IP',null=True)
    SubmitTime = models.DateTimeField(verbose_name='评论发布时间')
    class Meta:
        verbose_name = " 评论表"
    def __unicode__(self):
        return self.CommentId    
        
        
#商品
class Article_Goods(models.Model):
    GoodsId = models.CharField(max_length=36,primary_key=True,verbose_name='商品ID')
    ContentId = models.ForeignKey(Article_Content,verbose_name='内容Id')
    Standard = models.CharField(max_length=100,verbose_name='规格',null=True)
    GoodsModel = models.CharField(max_length=100,verbose_name='型号',null=True)
    Price = models.DecimalField(max_digits=10,decimal_places=2,verbose_name='价格')
    TxtId = models.CharField(max_length=36,verbose_name='详细',null=True)
    class Meta:
        verbose_name = " 商品"
    def __unicode__(self):
        return self.GoodsId    
        

#商品图片
class Article_GoodsImage(models.Model):
    GoodsImageId = models.CharField(max_length=36,primary_key=True,verbose_name='流水号')
    ContentId = models.ForeignKey(Article_Content,verbose_name='内容Id')
    GoodsId = models.ForeignKey(Article_Goods,verbose_name='商品Id')
    FileId = models.CharField(max_length=36,verbose_name='图片Id')
    Sno = models.IntegerField(verbose_name='图片排序')
    class Meta:
        verbose_name = "商品图片"
    def __unicode__(self):
        return self.GoodsImageId    
        
#图片新闻表
class Article_Image(models.Model):
    ImageId = models.CharField(max_length=36,primary_key=True,verbose_name='ImageId')
    ContentId = models.ForeignKey(Article_Content,verbose_name='内容Id')
    Ttile = models.CharField(max_length=100,verbose_name='标题',null=True)
    Explain = models.CharField(max_length=500,verbose_name='说明',null=True)
    FileId = models.CharField(max_length=36,verbose_name='图片Id')
    TopNum = models.IntegerField(verbose_name='图片排序')
    class Meta:
        verbose_name = "图片新闻表"
    def __unicode__(self):
        return self.ImageId    
        
#招聘
class Article_Job(models.Model):
    JodId = models.CharField(max_length=36,primary_key=True,verbose_name='JodId')
    ContentId = models.ForeignKey(Article_Content,verbose_name='内容Id')
    RecruitingNumbers = models.IntegerField(verbose_name='招聘人数',null=True)
    Position = models.CharField(max_length=50,verbose_name='职位',null=True)
    Salary = models.CharField(max_length=50,verbose_name='工资',null=True)
    Place = models.CharField(max_length=50,verbose_name='工作地点',null=True)
    Duty = models.CharField(max_length=500,verbose_name='职责',null=True)
    Require = models.CharField(max_length=500,verbose_name='说明',null=True)
    Phone = models.CharField(max_length=20,verbose_name='联系电话',null=True)
    class Meta:
        verbose_name = "招聘"
    def __unicode__(self):
        return self.JodId
        
#普通新闻
class Article_News(models.Model):
    Newid = models.CharField(max_length=36,primary_key=True,verbose_name='Newid')
    ContentId = models.ForeignKey(Article_Content,verbose_name='内容Id')
    Author = models.CharField(max_length=50,verbose_name='作者',null=True)
    Source = models.CharField(max_length=50,verbose_name='来源',null=True)
    TxtId = models.CharField(max_length=36,verbose_name='详细',null=True)
    class Meta:
        verbose_name = "普通新闻"
    def __unicode__(self):
        return self.Newid    
        
#软件下载
class Article_Soft(models.Model):
    SoftId = models.CharField(max_length=36,primary_key=True,verbose_name='SoftId')
    ContentId = models.ForeignKey(Article_Content,verbose_name='内容Id')
    Title = models.CharField(max_length=70,verbose_name='软件名称')
    SoftSize = models.IntegerField(verbose_name='软件大小K')
    Version = models.CharField(max_length=50,verbose_name='版本号',null=True)
    Developers = models.CharField(max_length=50,verbose_name='开发商',null=True)
    DevelopersWeb = models.CharField(max_length=200,verbose_name='开发商网站',null=True)
    Language = models.CharField(max_length=50,verbose_name='语言',null=True)
    OperatingEnvironment = models.CharField(max_length=50,verbose_name='运行环境',null=True)
    Down = models.IntegerField(verbose_name='下载次数')
    Explain = models.CharField(max_length=500,verbose_name='软件介绍',null=True)
    FilesId = models.CharField(max_length=36,verbose_name='软件文件ID')
    FileImageId = models.CharField(max_length=36,verbose_name='软件截图ID')
    class Meta:
        verbose_name = "软件下载"
    def __unicode__(self):
        return self.SoftId    
        
       
#专题
class Article_Topic(models.Model):
    TopicId = models.CharField(max_length=36,primary_key=True,verbose_name='TopicId')
    TopicTitle = models.CharField(max_length=200,verbose_name='专题名称')
    FileId = models.CharField(max_length=36,verbose_name='专题图片')
    TxtId = models.CharField(max_length=36,verbose_name='专题介绍',null=True)
    class Meta:
        verbose_name = "专题"
    def __unicode__(self):
        return self.TemplateName

#专题和内容对应表
class Article_Content_And_Topic(models.Model):
    RowId = models.CharField(max_length=36,primary_key=True,verbose_name='RowId')
    TopicId =models.ForeignKey(Article_Topic,verbose_name='专题ID')
    ContentId = models.ForeignKey(Article_Content,verbose_name='内容ID')
    Sno = models.IntegerField(verbose_name='排序')
    IsTopNum = models.BooleanField(verbose_name='是否置顶')
    class Meta:
        verbose_name = "专题和内容对应表"
    def __unicode__(self):
        return self.RowId

#投票表
class Article_Vote(models.Model):
    VoteId = models.CharField(max_length=36,primary_key=True,verbose_name='VoteId')
    ContentId = models.ForeignKey(Article_Content,verbose_name='内容ID')
    Explain = models.CharField(max_length=800,verbose_name='说明',null=True)
    IsMultiple = models.BooleanField(verbose_name='是否多选')
    IsAnonymous = models.BooleanField(verbose_name='是否可以匿名投票')
    IntervalTime = models.IntegerField(verbose_name='每次投票的间隔时间')
    IsMiscellaneous = models.BooleanField(verbose_name='是否包括其他')
    TypeId = models.IntegerField(verbose_name='投票类型') #enum 1 单选 Radio   2 多选  choice 3 文本 Txt
    class Meta:
        verbose_name = "视频新闻"
    def __unicode__(self):
        return self.VoteId

#投票选项表
class Article_Vote_Option(models.Model):
    OptionId = models.CharField(max_length=36,primary_key=True,verbose_name='OptionId')
    ContentId = models.ForeignKey(Article_Content,verbose_name='内容ID')
    VoteId = models.ForeignKey(Article_Vote,verbose_name='投票ID')
    OptionTxt = models.CharField(max_length=100,verbose_name='选项内容')
    Votes = models.IntegerField(verbose_name='得票')
    IsMiscellaneous = models.BooleanField(verbose_name='是否包括其他')
    class Meta:
        verbose_name = "投票选项表"
    def __unicode__(self):
        return self.OptionId                
        
        
#投票记录
class Article_Vote_Log(models.Model):
    RowId = models.CharField(max_length=36,primary_key=True,verbose_name='RowId')
    UserId = models.ForeignKey(User_Account,verbose_name='用户')
    ContentId = models.ForeignKey(Article_Content,verbose_name='内容ID')
    VoteId = models.ForeignKey(Article_Vote,verbose_name='投票ID')
    OptionId = models.ForeignKey(Article_Vote_Option,verbose_name='选项ID')
    Ip = models.IPAddressField(verbose_name='用户IP',null=True)
    SubmitTime = models.DateTimeField(verbose_name='投票时间')
    Contents = models.CharField(max_length=500,verbose_name='投票内容',null=True)
    class Meta:
        verbose_name = "投票记录"
    def __unicode__(self):
        return self.VoteId        



        
def enum(*sequential, **named):
    enums = dict(zip(sequential, range(len(sequential))), **named)
    return type('Enum', (), enums)
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
